package com.gmgx.hrms.biz.impl;

import com.gmgx.hrms.biz.ResignBiz;
import com.gmgx.hrms.dao.EmpDao;
import com.gmgx.hrms.dao.ResignDao;
import com.gmgx.hrms.dao.impl.EmpDaoImpl;
import com.gmgx.hrms.dao.impl.ResignDaoImpl;
import com.gmgx.hrms.entity.Resign;

import java.time.LocalDate;
import java.util.List;

public class ResignBizImpl implements ResignBiz {
private ResignDao dao=new ResignDaoImpl();
private EmpDao dao2=new EmpDaoImpl();
    @Override
    public boolean applyResignForEmp(Resign resign) {
        //是否当前用户已经存在等待审批的离职记录
          if (dao.queryResignByEmpId(resign.getResign_emp().getEmp_id())){
              //说明不能申请离职
              System.out.println("存在已经处于审批状态或者已经结束的离职记录，无法申请离职");
              return false;
          }
          else{
               //获取当前的系统日期
              LocalDate localDate=LocalDate.now();
            if(resign.getResign_date().isAfter(localDate)){
              return dao.addResignForEmp(resign);
            }else{
                System.out.println("离职的时间不能早于当前的系统时间");
                return false;
            }
          }

    }

    @Override
    public List<Resign> getAllResignByStatus(String status) {
        return dao.queryResignByStatus(status);
    }

    @Override
    public boolean editResignForHR(Resign resign) {
       //1 判断系统当前日期是否与其离职日期一致，如果不一致则无法正常离职
          if(resign.getResign_date().equals(LocalDate.now())){
              //才能执行离职操作
             if(dao2.updateEmpStatusByEmpid("离职",resign.getResign_emp().getEmp_id())){
                 if(dao.updateResignStatusByResignId(resign.getResign_id(),"5")){
                     return  true;
                 }
             }
           return false;
          }else{
              System.out.println("尚未到离职日期，无法进行离职操作");
              return false;
          }

    }
}
